package com.general.run.atomic;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferentTest {



    public static void main(String[] args) {
        Person p1 = new Person(101);
        Person p2 = new Person(102);

        AtomicReference<Object> ar = new AtomicReference<>(p1);
        ar.compareAndSet(p1,p2);

        Person p3 = (Person) ar.get();
        System.out.println("p3 is"+p3);

        System.out.println("p2.euals p3 is"+p2.equals(p3));
    }



}

class Person{
    volatile long id;

    public Person(long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                '}';
    }
}
